<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
    <jsp:include page="../incHead.jsp">
        <jsp:param name="title" value="forest.title" />
    </jsp:include>
    <body>
        <jsp:include page="../incHeader.jsp"/>
        <div id="container">
            <jsp:include page="../incMenu.jsp"/>    
            <div id="content">
                <div class="divOfForms">
                    <div id="title_subsection">
                        <h3><fmt:message key="forest.title"/></h3>
                    </div>
                    <form:form action="addForest" method="GET">
                        <table class="tableOfForms">
                            <tr>
                                <td class="outputInTable"><form:label path="name"><fmt:message key="forest.name"/></form:label></td>
                                <td><form:input path="name" /></td>
                                <td><form:errors class="error" path="name" cssClass="error"/></td>
                            </tr>
                            <tr>
                                <td class="outputInTable"><form:label path="locationInfo"><fmt:message key="forest.locInfo"/></form:label></td>
                                <td><form:input path="locationInfo" /></td>
                                <td><form:errors class="error" path="locationInfo" cssClass="error" /></td>
                            </tr>
                            <tr>
                                <td></td>
                                <td><input type="submit" value=<fmt:message key="general.submit"/> /></td>
                                <td></td>
                            </tr>
                        </table>
                    </form:form>
                </div>
                <p class="error">${error}</p>
                <br/>
                <div class="divOfItems">
                    <div id="title_subsection">
                        <h3><fmt:message key="forest.all"/></h3>
                    </div>
                    <table class="allTable">
                        <th><fmt:message key="forest.name"/></th>
                        <th><fmt:message key="forest.locInfo"/></th>
                        <sec:authorize access="hasRole('ROLE_ADMIN')">
                        <th colspan="2"><fmt:message key="general.action"/></th>
                        </sec:authorize>
                        <c:forEach var="forest" items="${forests}" >
                            <tr>
                                <td><c:out value="${forest.name}" /></td>
                                <td><c:out value="${forest.locationInfo}" /></td>
                                <sec:authorize access="hasRole('ROLE_ADMIN')">
                                <td><a href="editForest?id=${forest.id}"><fmt:message key="general.edit"/></a></td>
                                <td><a href="removeForest?id=${forest.id}" 
                                       onclick="return confirm('Are you sure you want to delete ${forest.name}?')">
                                        <fmt:message key="general.remove"/></a></td>
                                </sec:authorize>
                            </tr>
                        </c:forEach>
                    </table>    
                </div>
            </div>
        </div>
    </body>
</html>